package com.aso114.project.mvp.activity.fragment;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.aso114.project.R;
import com.aso114.project.base.BaseFragment;
import com.aso114.project.bean.CourseBean;


/**
 * Created by hp on 2017/10/31.
 */

public class TabFragment extends BaseFragment {
    private static final String KEY="EXTRA";
    private CourseBean courseBean;
    private WebView webView;

    @Override
    protected int getLayoutResourceId() {
        return R.layout.layout_tab;
    }

    @Override
    public void initView() {
        Bundle bundle=getArguments();
        String url="http://www.baidu.com";
        if(bundle!=null) {
            courseBean=(CourseBean)bundle.getSerializable(KEY);
//            url=courseBean.getHref();
        }
        webView = (WebView) getView().findViewById(R.id.webView);
        //webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);//设置支持javascript
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);//支持缩放
        webSettings.setAllowFileAccess(true); // 允许访问文件
        //webSettings.supportMultipleWindows();//多窗口
        webSettings.setLoadsImagesAutomatically(true);//自动加载图片
        webSettings.setLoadWithOverviewMode(true);//适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        //webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL.SINGLE_COLUMN);
        webSettings.setUseWideViewPort(true);//
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT );
        webView.loadUrl(url);//127a5bd99d694f11bf444dc6076cd020" );//+ articleBean.getId()
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;

            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void addOnClick() {

    }

    public static TabFragment newInstance(CourseBean extra){
        Bundle bundle=new Bundle();
        bundle.putSerializable(KEY,extra);
        TabFragment fragment=new TabFragment();
        fragment.setArguments(bundle);
        return  fragment;
    }

}
